#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/4 14:34
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : square_morphology.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage.io import imread
from skimage.morphology import square, binary_erosion, binary_dilation
from DIP_experiment_5.util import contrast_show

FONT_PATH = "C:/Windows/Fonts/simhei.ttf"
IM_PATH = "../experiment_fig/square.tif"  # binary image
im = imread(IM_PATH)
square_elem = square(width=13)  # 生成13*13的正方型结构元素
eroded_im = binary_erosion(im, square_elem)  # 对原始图像进行腐蚀操作
dilated_im = binary_dilation(eroded_im, square_elem)  # 对已腐蚀图像做膨胀操作
im_dict = {"原始图像": im, "二值腐蚀图像": eroded_im, "二值膨胀图像": dilated_im}
contrast_show(im_dict, (1, 3), wspace=0.3, font=FONT_PATH)
